#coding:utf8
from kcalerter.dbconnmysql import connDB, connClose
from kcalerter.alerLogger import mylogg


#添加
'''
def insertbysql(insersql):
    insersql="insert into spider_user(name,pwd,type,email,alertType,deleted) values('test1','123456','1','870641581@qq.com','1',0)"
    try:
            conn,cur=connDB()
            result= exeUpdate(conn, cur, insersql);
            conn.commit();
            print(result);
    except Exception:
            print("添加失败");
            raise;
    finally:
            connClose(conn, cur)
    return result
#修改
def updatebyalertType(alertType,ids):
    updatesql="update spider_user set alert_type='"+alertType+"' where id in ("+ids+")"
    try:
            conn,cur=connDB()
            result= cur.execute(updatesql);
            conn.commit();
            print(result);
    except Exception , e:
            print e
            print("更新失败");
            raise;
    finally:
            connClose(conn, cur)
    return result
#根据id查询用户信息
def querybyid(idq):
    queryidsql="select * from spider_user where id in("+idq+")"
    try:
            conn,cur=connDB()
            cur.execute(queryidsql);
            result= cur.fetchall()
            print(result);
    except Exception , e:
            print e
            print("查询失败");
            raise;
    finally:
            connClose(conn, cur)
    return result
'''
#根据所有用户信息
def queryuserlist():
    queryidsql="select * from spider_user where deleted=0"
    try:
            conn,cur=connDB()
            cur.execute(queryidsql);
            result= cur.fetchall()
            print(result);
    except Exception,err:
            print("query not delete all users(table spider_alert_rule)"+err)
            mylogg("query not delete all users(table spider_alert_rule)"+err)
            raise;
    finally:
            connClose(conn, cur)
    return result
'''
#删除
def deletebyid(ids):
        try:
            conn,cur=connDB()
            result=exeDelete(conn, cur, ids);
            conn.commit();
            print("删除成功");
        except Exception:
            print("删除失败");
            raise;
        finally:
            connClose(conn, cur)
        return result
'''